// index.js
// 获取应用实例
Page({
  data: {
    menuItem: [],
    value: '',
    list: [
      {
        active: "/pages/index/index",
        text: "首页",
        icon: "home-o"
      }, {
        active: "/pages/syudy/index",
        text: "在线学习",
        icon: "search"
      },
      {
        active: "/pages/integral/index",
        text: "积分",
        icon: "friends-o"
      },
      {
        active: "/pages/user/index",
        text: "我的",
        icon: "setting-o"
      }
    ],
    active: 0,
    type: '',
    articleList: [],
    quList: [],
    orderList: [],
    message: ''
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    this.setData({ active: event.detail });
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad(e) {
    this.nowArticle();
    this.nowQu();
    this.getOrder();
    this.getMessage();
  },
  onShow() {
  },
  //轮播图
  getSwiperImag() {
  },
  goToList(e) {
    let type = e.currentTarget.dataset.type;
    if (type == '面试宝典') {
      wx.navigateTo({
        url: '/packageB/pages/syudy/skill/index',
      })
    }
    if (type == '精彩文章') {
      wx.navigateTo({
        url: '/packageA/pages/repository/list/index',
      })
    }
    if (type == '开源项目') {
      wx.navigateTo({
        url: '/packageA/pages/open/list/index',
      })
    }
    if (type == '接单专区') {
      wx.navigateTo({
        url: '/packageC/pages/order/list/index',
      })
    }
    if (type == '资源区') {
      wx.navigateTo({
        url: '/packageA/pages/file/list/index',
      })
    }
  },
  interview() {

  },
  //最新文章
  nowArticle() {
    wx.http.get(getApp().globalData.xcxNowList).then(res => {
      if (res.code == 200) {
        this.setData({
          articleList: res.rows
        })
      }
    })
  },
  //查看更多 
  seeArticleMore() {
    wx.navigateTo({
      url: '/packageA/pages/repository/list/index',
    })
  },

  //文章详情
  articleDetail(e) {
    wx.navigateTo({
      url: '/packageA/pages/repository/list/detail/index?id=' + e.currentTarget.dataset.id,
    })
  },
  //最新题目
  nowQu() {
    wx.http.get(getApp().globalData.queryNowAll).then(res => {
      if (res.code == 200) {
        this.setData({
          quList: res.data
        })
      }
    })
  },
  //查看更多
  seeQuMore() {
    wx.navigateTo({
      url: '/packageB/pages/syudy/interview/select/index',
    })
  },
  //题目详情
  quDetail(e) {
    wx.setStorageSync('quId', e.currentTarget.dataset.id);
    wx.setStorageSync('quBankId', e.currentTarget.dataset.qubankid);
    wx.navigateTo({
      url: '/packageB/pages/syudy/interview/detail/index',
    })
  },

  //最新订单

  getOrder() {
    wx.http.get(getApp().globalData.getOrderList, {
      pageNum: 1,
      pageSize: 3
    }).then(res => {
      if (res.code == 200) {
        if (this.data.orderList.size == 0) {
          this.setData({
            orderList: res.rows
          })
        } else {
          if (res.total == 0) {
            this.setData({
              orderList: []
            })
          } else {
            this.setData({
              orderList: this.data.orderList.concat(res.rows)
            })
          }
        }
      }
    })
  },
  //订单详情
  gotoOrderDetail(e) {
    wx.setStorageSync('orderTakingId', e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/packageC/pages/order/detail/index',
    })
  },
  //去订单页面
  gotoOrder() {
    wx.navigateTo({
      url: '/packageC/pages/order/list/index',
    })
  },
  //获取消息通知
  getMessage() {
    wx.http.get(getApp().globalData.getMessageNotification + '/message.notification').then(res => {
      this.setData({
        message: res.msg
      })
    })

  }
})
